package sort

type ShellSort struct {
	BaseSort
}

// Sort 希尔排序重点是分组  不断控制迭代的分段 组内排序后就是有序
func (self ShellSort) Sort() {

	length := self.Len()
	array := self.Array
	// 数组分组
	for segment := length / 2; segment > 0; segment /= 2 {
		//组内排序
		for i := segment; i < length; i++ {
			temp := array[i] //
			k := i - segment
			//排序
			for k >= 0 && self.Less(i, k) {
				array[k+segment] = array[k]
				k -= segment
			}
			array[k+segment] = temp
		}
	}

}

func (self ShellSort) Name() string {
	return "希尔排序"
}
